﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Shipping : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Page.Form.DefaultFocus = txtName.ClientID;
            Page.Form.DefaultButton = cmdShipFormSubmit.UniqueID;

            // Populate fields with existing shipping info
            if (Session["ShippingData"] != null)
            {
                ShippingData shipping = (ShippingData)Session["ShippingData"];
                txtName.Text = shipping.FullName;
                txtStreet1.Text = shipping.Street1;
                txtStreet2.Text = shipping.Street2;
                txtCity.Text = shipping.City;
                ddState.SelectedValue = shipping.State;
                txtZip.Text = shipping.Zip;
            }
        }
    }
    protected void cmdShipFormSubmit_Click(object sender, EventArgs e)
    {
        //check for valid page
        if (!Page.IsValid) { return; }

        ShippingData shipping = new ShippingData();
        shipping.FullName = txtName.Text.ToString();
        shipping.Street1 = txtStreet1.Text.ToString();
        shipping.Street2 = txtStreet2.Text.ToString();
        shipping.City = txtCity.Text.ToString();
        shipping.State = ddState.SelectedValue.ToString();
        shipping.Zip = txtZip.Text.ToString();

        Session["ShippingData"] = shipping;

        Response.Redirect("Checkout.aspx"); 
    }
    protected void cmdShipFormCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
